home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / linker / main.ml < prev    next >
Encoding:
Text File  |  1993-09-24  |  2.2 KB  |  84 lines  |  [TEXT/MPS ]

  1. (* The Caml Light linker. Command-line parsing. *)
  2.  
  3. #open "config";;
  4. #open "misc";;
  5. #open "symtable";;
  6. #open "link";;
  7.  
  8. let object_files = ref ([] : string list)
  9. and exec_file = ref default_exec_name
  10. and prim_file = ref ""
  11. ;;
  12.  
  13. let anonymous s =
  14.   let name =
  15.     if filename__check_suffix s ".ml" then
  16.       filename__chop_suffix s ".ml" ^ ".zo"
  17.     else
  18.       s in
  19.   object_files := name :: !object_files
  20. ;;
  21. let set_stdlib p =
  22.   path_library := p;
  23.   load_path := [!path_library]
  24. and add_include d =
  25.   load_path := d :: !load_path
  26. and set_debug () =
  27.   write_symbols := true
  28. and set_exec_file e =
  29.   exec_file := e
  30. and set_custom f =
  31.   custom_runtime := true;
  32.   prim_file := f
  33. and show_version () =
  34.   prerr_string version__banner; prerr_endline ""; exit 0
  35. and process_include filename =
  36.   do_list anonymous (readword__from_file filename)
  37. and process_require filename =
  38.   let rec require = function
  39.     [] ->
  40.       ()
  41.   | "val"::qual::id::rest ->
  42.       require_qualid qual id; require rest
  43.   | "prim"::name::rest ->
  44.       let n = get_num_of_prim name in require rest
  45.   | _ ->
  46.       fatal_error "bad require file"
  47.   in require (readword__from_file filename)
  48. ;;
  49.  
  50. let main() =
  51. try
  52.   sys__catch_break true;
  53.   load_path := [!path_library];
  54.   reset_linker_tables();
  55.   arg__parse ["-stdlib", arg__String set_stdlib;
  56.               "-I", arg__String add_include;
  57.               "-include", arg__String add_include;
  58.               "-g", arg__Unit set_debug;
  59.               "-debug", arg__Unit set_debug;
  60.               "-o", arg__String set_exec_file;
  61.               "-exec", arg__String set_exec_file;
  62.               "-custom", arg__String set_custom;
  63.               "-v", arg__Unit show_version;
  64.               "-version", arg__Unit show_version;
  65.               "-files", arg__String process_include;
  66.               "-require", arg__String process_require;
  67.               "-", arg__String anonymous]
  68.              anonymous;
  69.   link (rev !object_files) !exec_file;
  70.   if !custom_runtime then begin
  71.     let oc = open_out !prim_file in
  72.     output_primitives oc;
  73.     close_out oc
  74.   end;
  75.   exit 0
  76.  
  77. with Toplevel -> exit 2
  78.    | sys__Break -> exit 3
  79.    | Zinc s -> prerr_string "# Internal error: "; prerr_endline s; exit 4
  80. ;;
  81.  
  82. printexc__f main ()
  83. ;;
  84.